<?php
/**
 * @package YEAP project's Helpers subsystem
 * @name User Error helpers
 *
 * @license GPL v.2
 * @copyright (cc) VS aka Virtual Stalker, 2009
 *
 * */

//	см. /config/ini_set.php

if (! function_exists('_notice') )
{
	function _notice($str='')
	{
		$le = error_get_last();
		$msg = date(DATETIME_FORMAT)
			.' E_USER_NOTICE: '
			. $str .'. File: '.$le['file'].', line: '.$le['line'];
		_error($msg,E_USER_NOTICE);
		return false;
	}
}
if (! function_exists('_warning') )
{
	function _warning($str='')
	{
		$le = error_get_last();
		$msg = date(DATETIME_FORMAT)
			.' E_USER_WARNING: '
			. $str .'. File: '.$le['file'].', line: '.$le['line'];
		_error($msg,E_USER_WARNING);
		return false;
	}
}

if (! function_exists('_error') )
{
	function _error($str='',$type=E_USER_ERROR, $backtrace=false, $trigger=true)
	{
		$le = error_get_last();
		$msg = date(DATETIME_FORMAT)
			.(E_USER_ERROR==$type?' E_USER_ERROR: ':' type='.$type.' ')
			. $str ."\r\n File: ".$le['file'].', line: '.$le['line']
			.($backtrace ? "\r\n". var_export(debug_backtrace(),true)."\r\n" : "\r\n" );
		//debug_print_backtrace();
		if ($trigger)
		{
			error_log($msg,3,ERROR_LOG);
			//@ trigger_error($msg,$type);	// чтоб не было нотисов
		}
		return $msg;

	// не будем пока усложнять процесс

	/*
		// be sure that the supplied parameter is a string and not empty
		if (empty ($msg) || !is_string ($msg))
		{
			throw new ErrorException ('Invalid parameter supplied to ReportError', 0, E_ERROR);
		}

		// retrieve error settings
		$display    = strtolower (ini_get ('display_errors'));
		$log        = strtolower (ini_get ('log_errors'));

		// check if we're displaying errors
		if ($display === 'on' || $display === '1' || $display === 1 || $display === 'true' || $display === true)
		{
			echo $msg;
		}

		// check if we're logging errors
		if ($log === 'on' || $log === '1' || $log === 1 || $log === 'true' || $log === true)
		{
			$result = error_log ($msg);

			// check for error while logging
			if (!$result)
			{
				throw new ErrorException ('Attempt to write message to error log failed in ReportError', 0, E_ERROR);
			}
		}
		*/
	}
}

?>